Skip to content

Unify pointer events and support tablet event - #3417

Draft
443eb9 wants to merge 8 commits into
iced-rs:masterfrom
443eb9:unify-pointer-event
Draft

Unify pointer events and support tablet event#3417
443eb9 wants to merge 8 commits into
iced-rs:masterfrom
443eb9:unify-pointer-event

Conversation

@443eb9

@443eb9 443eb9 commented Aug 11, 2026

Copy link
Copy Markdown

This pr is based on #3415 so the file changes are mixed with it but this will be rebased after winit upgrade.

Discussion in discord thread: https://discord.com/channels/628993209984614400/1536327987837014098

winit 0.31 has its pointer events overhauled, and the api changed a lot. It now looks like this

pub enum WindowEvent
    PointerMoved {
        device_id: Option<DeviceId>,
        position: PhysicalPosition<f64>,
        source: PointerSource,
    },
    PointerEntered {
        device_id: Option<DeviceId>,
        position: PhysicalPosition<f64>,
        primary: bool,
        kind: PointerKind,
    },
    PointerLeft {
        device_id: Option<DeviceId>,
        position: Option<PhysicalPosition<f64>>,
        primary: bool,
        kind: PointerKind,
    },
    PointerButton {
        device_id: Option<DeviceId>,
        state: ElementState,
        position: PhysicalPosition<f64>,
        primary: bool,
        button: ButtonSource,
        is_macos_activation_click: bool,
    },
}

While it previously looks like this:

pub enum WindowEvent {
    CursorMoved {
        device_id: DeviceId,
        position: PhysicalPosition<f64>,
    },
    CursorEntered { device_id: DeviceId },
    CursorLeft { device_id: DeviceId },
    MouseInput { device_id: DeviceId, state: ElementState, button: MouseButton },
    Touch(Touch),
}

iced is currently using winit 0.30 and following the old style of api.

pub enum Event {
    Mouse(mouse::Event),
    Touch(touch::Event),
}

This pr merged the old Mouse and Touch variant on Event into Pointer:

pub enum Event {
    PointerEntered {
        position: Point,
        kind: pointer::Kind,
    },
    PointerLeft {
        kind: pointer::Kind,
    },
    PointerMoved {
        position: Point,
        source: pointer::Source,
    },
    PointerPressed {
        position: Point.
        button: button::Source,
    },
    PointerReleased {
        position: Point,
        button: button::Source,
    },
    WheelScrolled {
        delta: mouse::ScrollDelta,
    },
}

also added four helpers to make matching cleaner and make touch and tablet press support out of box.

    pub fn is_primary_click(&self) -> bool { ... }
    pub fn is_primary_release(&self) -> bool { ... }
    pub fn is_secondary_click(&self) -> bool { ... }
    pub fn is_secondary_release(&self) -> bool { ... }

Previously if we want to match left click or finger press:

iced_core::Event::Mouse(mouse::Button::Left) | iced_core::Event::Touch(_) => { ... }

Now:

iced_core::Event::Pointer(event) if event.is_primary_click => { ... }

Even with tablet contact supported out of box!

@443eb9
443eb9 marked this pull request as draft August 11, 2026 12:52
@443eb9 443eb9 changed the title Unify pointer event Unify pointer events Aug 11, 2026
@443eb9 443eb9 changed the title Unify pointer events Unify pointer events and support tablet event Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant